package yl.hs.bmipfull.daos.finance;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import yl.hs.bmipfull.daos.BaseDao;
import yl.hs.bmipfull.pojo.finance.MoneyTradeEntity;
import yl.hs.bmipfull.pojo.finance.ReceivePaymentRecordEntity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * IReceivePaymentRecordDao 采购付款记录数据接口
 * @category 财务管理-采购付款记录
 * @author 谢景广
 * @date 2022-01-08
 */
@Repository
public interface IReceivePaymentRecordDao extends BaseDao<ReceivePaymentRecordEntity> {

    /**
     * 根据合同sn合计收款金额
     * @param contractSn 合同Sn
     * @return 合计金额
     */
    BigDecimal sumAmountByContractSn(String contractSn);


    /**
     * 根据sn修改付款记录信息状态
     *
     * @param snArray 付款记录sn数组
     * @param state 状态
     * @return 执行结果
     */
    Integer changeStateBySn(@Param("snArray") String[] snArray, short state);



    /**
     *  分页查询收款记录表信息
     *  @param map 查询条件 {@link ReceivePaymentRecordEntity}
     *  @return 站内信息-List<{@link ReceivePaymentRecordEntity}>
     */
    List<ReceivePaymentRecordEntity> queryPage(@Param("map") Map<String, Object> map);
    /**
     * 根据查询条件统计数据数量
     * @param map 查询条件
     * @return 数据数量
     */
    Integer queryCountByCondition(@Param("map") Map<String, Object> map);
    /**
     * 根据查询条件统计数据数量
     * @param map 查询条件
     * @return 数据数量
     */
    Integer queryCountByContractSN(@Param("map") Map<String, Object> map,@Param("snList")List<String> snList);
    /**
     *  分页查询收款记录表信息
     *  @param map 查询条件 {@link ReceivePaymentRecordEntity}
     *  @return 站内信息-List<{@link ReceivePaymentRecordEntity}>
     */
    List<ReceivePaymentRecordEntity> queryPageContractSN(@Param("map") Map<String, Object> map,@Param("snList")List<String> snList);
    Integer queryRecordCountByQuery(@Param("map")Map<String, Object> query);

    List<MoneyTradeEntity> queryRecordPageByQuery(@Param("map")Map<String, Object> query);

    /**
     *  获取收付款信息
     * @param tradeType 交易类型 1.收款  0.付款
     * @return 金额
     */
    @Select("SELECT COALESCE(SUM(tradeAmount),0) from receive_payment_record WHERE state >=0 and tradeType=#{tradeType}")
    BigDecimal getSumTradeAmountByTradeType(int tradeType);


    BigDecimal getSumTradeAmountByDate(int tradeType,int dateType);

    BigDecimal getSumTradeAmountByContractSN(@Param("snArray") String[] snArray);

    BigDecimal queryContractReceiveAmount(String contractSN, Date startTime);

    BigDecimal getMonthCollection();

    BigDecimal getLastMonthSubtract();

    Object getMonthlyCollectionTrend(Date time);


    BigDecimal getNetReceipts(String contractSN);

    BigDecimal getPayableMonth();

    BigDecimal getPaidMonthContractSN();

    BigDecimal getCumulativeCopeWith();

    BigDecimal getMonthlyPayment( Date time);

    BigDecimal getNetReceiptsFu(String contractSN);

    List<ReceivePaymentRecordEntity> queryByContractSnAndTime(String contractSn,Date tradeTime);
}
